package com.xiang.atomikos.controller;

import com.xiang.atomikos.entity.UserEntity;
import com.xiang.atomikos.service.AddUserOneService;
import com.xiang.atomikos.service.AddUserTwoService;
import com.xiang.atomikos.service.UserEntityTestService;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Slf4j
public class ApplicationTestController {

  @Resource
  AddUserOneService oneService;
  @Resource
  UserEntityTestService entityTestService;
  @Resource
  AddUserTwoService twoService;

  /**
   *  异常会插入
   */
  @PostMapping("save")
  public void TestSave(){
    UserEntity user1=new UserEntity();
    user1.setLoginName("zhangsan");
    user1.setPasswd("123456");
    user1.setUserName("zs");
    oneService.saveOne(user1);
    int a= 1/0;
    twoService.saveTwo(user1);
  }


  /**
   *  异常不插入
   */
  @RequestMapping("testService")
  public void testDoubleSave(){
    UserEntity user2=new UserEntity();
    user2.setLoginName("wangwuserver");
    user2.setPasswd("123456");
    user2.setUserName("ww");
    int res = entityTestService.save(user2);
    log.info("res:: {}",res);
  }



}
